﻿
define(function (require, exports, module) {
    require('plugins/zTree/css/zTreeStyle/metro.css');
    require('plugins/zTree/js/jquery.ztree.all-3.5.min');
    var zTree;
    var setting = {
        check: {
            enable: true
        },
        view: {
            dblClickExpand: false,
            showLine: false,
            showIcon:false,
            selectedMulti: false
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pId",
                rootPId: ""
            }
        },
        callback: {
            beforeCollapse: function () {
                return false;
            },
            beforeClick: function (treeId, treeNode) {
                if (treeNode.checked)
                    zTree.checkNode(treeNode, false, true);
                else
                    zTree.checkNode(treeNode, true, true);
            }
        }
    };

    module.exports = {
        init: function (jq, nodeData) {
            zTree = $.fn.zTree.init(jq, setting, nodeData);
            zTree.expandAll(true);
        },
        checkAllNodes: function (checked) {
            zTree.checkAllNodes(checked);
        },
        getCheckedNodes: function (checked) {
            return zTree.getCheckedNodes(checked);
        },
        getNodeByTId: function (tId) {
            return zTree.getNodeByTId(tId);
        },
        checkNode: function (treeNode, checked, checkTypeFlag, callbackFlag) {
            zTree.checkNode(treeNode, checked, checkTypeFlag, callbackFlag);
        }
    }
});